package com.dtner.common.entity;

import com.dtner.common.enums.ResultCodeEnum;

/**
 * @author: dt
 * @description: restful 接口返回对象实体类
 * @create: 2022-07-12 19:42
 */
public class ResultMessage <T> {

    /**
     * 接口返回 code
     */
    private Integer code;

    /**
     * 接口返回 msg
     */
    private String msg;

    /**
     * 接口返回具体数据
     */
    private T data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * 成功
     * @param data
     */
    public void success(T data) {
        ResultCodeEnum resultCode = ResultCodeEnum.Success;
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    /**
     * 错误
     * @param resultCode
     */
    public void error(ResultCodeEnum resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }

    /**
     * 错误
     * @param resultCode
     * @param msg
     */
    public void error(ResultCodeEnum resultCode, String msg) {
        this.code = resultCode.getCode();
        this.msg = msg;
    }

}
